<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" @open="open">
    <el-form
      ref="formRef"
      :model="formData"
      label-width="auto"
      v-loading="formLoading"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item label="表名称:" prop="table.tableName">
            {{ formData.table.tableName }}
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="表描述:" prop="table.tableComment">
            {{ formData.table.tableComment }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="className">
            <template #label>
              <span>
                实体类名称:
                <el-tooltip
                  content="默认去除表名的前缀。如果存在重复，则需要手动添加前缀，避免 MyBatis 报 Alias 重复的问题。"
                  placement="top"
                >
                  <Icon class="" icon="ep:question-filled" />
                </el-tooltip>
              </span>
            </template>
            {{ formData.table.className }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="作者:" prop="table.author">
            {{ formData.table.author }}
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注:" prop="table.remark">
            {{ formData.table.remark }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { propTypes } from '@/utils/propTypes'
import * as CodegenApi from '@/api/infra/codegen'
import { CodegenUpdateReqVO } from '@/api/infra/codegen'

defineOptions({ name: 'SourceDetail' })
const emit = defineEmits(['update:visible'])
const props = defineProps({
  visible: propTypes.bool.def(false),
  data: propTypes.object.def({}),
})
// 弹窗的是否展示
const dialogVisible = computed({
  get: () => props.visible,
  set: (val) => {
    emit('update:visible', val)
  },
})
// 弹窗的标题
const dialogTitle = ref('共享数据库查看')
const formLoading = ref(false)
const	formData = ref<CodegenUpdateReqVO | any>({
  table: {},
  columns: [],
})
const getDetail = () => {
  formLoading.value = true
  CodegenApi.getCodegenTable(props.data.id).then((data) => {
    // console.log('getDetail', data)
    const resData = data || {}
    formData.value = {
      ...resData,
      table: resData.table || {},
      columns: resData.columns || [],
    }
  }).finally(() => {
    formLoading.value = false
  })
}
const open = () => {
  getDetail()
}
</script>

<style lang="scss" scoped>
</style>
